#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=5e5+5,M=20;
int n,m;
int a[N];
int LOG[N],st[M][N];
inline int ask(int l,int r){
	int len=LOG[r-l+1];
	return min(st[len][l],st[len][r-(1<<len)+1]);
}
int s[N];
bool check(ll x){
	int tot=0;
	for(int i=1;i<=n;i++)
		if(a[i]*2<=x)s[++tot]=i;
	if(!tot)return 0;
	int sum=tot;
	for(int i=1;i<tot;i++)
		if(s[i]+1<s[i+1]&&((ll)max(a[s[i]],a[s[i+1]])+ask(s[i]+1,s[i+1]-1)<=x))
			sum++;
	int tmp=2e9;
	if(1<s[1])tmp=min(tmp,ask(1,s[1]-1));
	if(s[tot]<n)tmp=min(tmp,ask(s[tot]+1,n));
	if((ll)max(a[s[1]],a[s[tot]])+tmp<=x)
		sum++;
	return sum>=m;
}
signed main(){
	freopen("sub.in","r",stdin);
	freopen("sub.out","w",stdout);
	read(n,m);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=2;i<=n;i++)
		LOG[i]=LOG[i>>1]+1; 
	for(int i=1;i<=n;i++)
		st[0][i]=a[i];
	for(int i=1;i<M;i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
	ll l=0,r=2e9;
	while(l<r){
		if(check(mid))r=mid;
		else l=mid+1;
	}
	write(r);
	return flush(),0;
}
